
#include "NetItemHandler.h"
#include "NetMsgHandler.h"

#include "CreatureManager.h"
#include "GameDanger.h"


RECV_MSG_USE_ITEM gMsgUseItem;

fint32		NetSwitchItemHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_SWITCH_ITEM )
	
    if ( player->IsFighting() )
	{
		player->AddDanger( GAME_DESTRUCTIVELY_DANGER );
		return GAME_NO_ERROR;
	}

	player->SwitchItem( msg->i1 , msg->i2 );

	return GAME_NO_ERROR;
}

fint32		NetSwitchEquipHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_SWITCH_EQUIP )
	
    if ( player->IsFighting() )
	{
		player->AddDanger( GAME_DESTRUCTIVELY_DANGER );
		return GAME_NO_ERROR;
	}

	player->SwitchEquip( msg->i1 , msg->i2 );

	return GAME_NO_ERROR;
}



fint32		NetUseItemHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_USE_ITEM )
    
    if ( player->IsFighting() )
	{
		player->AddDanger( GAME_DESTRUCTIVELY_DANGER );
		return GAME_NO_ERROR;
	}

	fbool b = player->UseItem( msg->i , msg->p , msg->t );

	if ( b )
	{
		if ( msg->t == SAUIT_PLAYER )
		{
			gMsgUseItem.Base = player->GetFightData().Base;

			player->PackMsg( &gMsgUseItem );
			player->SendMsg();
		}
		else if ( msg->t == SAUIT_PET )
		{
			gMsgUseItem.Base = player->GetPet( msg->p )->GetFightData().Base;

			player->PackMsg( &gMsgUseItem );
			player->SendMsg();
		}
		else
		{
			
		}
	}
	
	return GAME_NO_ERROR;
}

fint32		NetDropEquipHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_DROP_EQUIP )
	
    if ( player->IsFighting() )
	{
		player->AddDanger( GAME_DESTRUCTIVELY_DANGER );
		return GAME_NO_ERROR;
	}

	player->DropEquip( msg->i1 , msg->i2 );

	gMsgUseItem.Base = player->GetFightData().Base;

	player->PackMsg( &gMsgUseItem );
	player->SendMsg();

	return GAME_NO_ERROR;
}
